<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/jsp/component/common.jsp" %>
<!DOCTYPE html>
<html>
<head>
  <title>大区新增</title>
  <meta charset="utf-8">
  <!-- Bootstrap Core CSS -->
  <link href="${css}/bootstrap.min.css" rel="stylesheet"/>
  <!-- bootstrapValidator验证 -->
  <link href="${assets}/bootstrapValidator/css/bootstrapValidator.css" rel="stylesheet"/>
</head>
<body style="width: 98%">
<form id="myForm" class="form-horizontal" method="post" >
    <input type="hidden" name="largeAreaCodeOld" value="${largeArea.largeAreaCode}" />
<%--    <div class="form-group">
        <label for="largeAreaCode" class="col-sm-2 control-label">大区编码</label>
        <div class="col-sm-10">
            <input type="text" class="form-control" id="largeAreaCode" name="largeAreaCode" value="${largeArea.largeAreaCode}"
                   placeholder="请输入大区编码">
        </div>
    </div>--%>
    <div class="form-group">
        <label for="largeAreaName" class="col-sm-2 control-label">大区名称</label>
        <div class="col-sm-10">
            <input type="text" class="form-control" id="largeAreaName" name="largeAreaName" value="${largeArea.largeAreaName}"
                   placeholder="请输入大区名称">
        </div>
    </div>
    <div class="modal-footer" style="text-align: center ">
        <button type="button" class="btn btn-default" data-dismiss="modal" id="closeModalButt">关闭</button>
        <button type="submit" class="btn btn-primary">保存</button>
    </div>
</form>

<!-- jQuery -->
<script src="${js}/jquery-1.9.1.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="${js}/bootstrap.min.js"></script>

<script src="${js}/bootbox.js"></script>
<!-- bootstrapValidator验证 -->
<script src="${assets}/bootstrapValidator/js/bootstrapValidator.js"></script>
<!-- bootstrapValidator验证 国际化中文 -->
<script src="${assets}/bootstrapValidator/js/language/zh_CN.js"></script>

<script type="text/javascript">
  $(document).ready(function() {
    $('#myForm').bootstrapValidator({
      message: 'This value is not valid',
      feedbackIcons: {
        valid: 'glyphicon glyphicon-ok',
        invalid: 'glyphicon glyphicon-remove',
        validating: 'glyphicon glyphicon-refresh'
      },
      fields: {
        largeAreaCode: {
          verbose: false,
          validators: {
            notEmpty: true,
            digits: true,
            remote: {
              type: "post",
              delay: 500,
              url: '${ctx}/area/validateLargeAreaCode',
              data: function (validator) {
                return {
                  largeAreaCode: validator.getFieldElements('largeAreaCode').val(),
                  exception: '${largeArea.largeAreaCode}'
                };
              },
              message: '该编码已存在'
            }
          }
        },
        largeAreaName: {
          validators: {
            notEmpty: true
          }
        }
      }
    }).on('success.form.bv', function (e) {
        e.preventDefault();
        $.ajax({
            url: '${URL_ADM_AREA_UPDATE}',
            type: 'post',
            data: $('#myForm').serialize(),
            async: false, //默认为true 异步
            error: function () {
                alert('error');
            },
            success: function (data) {
                window.parent.closeModal("update");//关闭弹出框并刷新父级表格数据
            }
        });
    });

      $("#closeModalButt").on("click",function(){
          window.parent.simpleCloseModal("update");
      });

  });

</script>
</body>
</html>